﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using BLL;
using Models;


namespace CMS项目.Areas.HouTaiArea.Controllers
{
    public class CMS_UserController : Controller
    {
        // GET: HouTaiArea/CMS_User
        private KQCMS db = new KQCMS();
        // GET: HouTaiArea/CMS_User
        public ActionResult Index()
        {
            return View();
        }
        //-------------------------------------------------------------------------------------
        public ActionResult Index1()
        {
            return View();
        }
        [HttpGet]
        public ActionResult SelectPage(int? pageindex, int? pagesize)
        {
            return Json(BLLCMS_User.GetPageCMS_Articles((int)pageindex, (int)pagesize, null), JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public ActionResult SelectPage(int? pageindex, int? pagesize, string Uname)
        {
            return Json(BLLCMS_User.GetPageCMS_Articles((int)pageindex, (int)pagesize, Uname));
        }
        //---------------------------------------------------------------------------------------
        //查询全部
        public ActionResult CMS_Userlist()
        {
            return View(BLLCMS_User.GetCMS_UserAll());
        }
        [HttpPost]
        public ActionResult CMS_Userlist(string Uname)
        {
            return View(BLLCMS_User.GetCMS_UserAllWhere(Uname));
        }
        //-------------------------------------------------------------------------
        public ActionResult Userindrx()
        {
            return View();
        }
        public ActionResult addindex()
        {
            return View();
        }
        //-------------------------------------------------------------
        [HttpPost]
        public ActionResult useradd(CMS_User c)
        {
            int st = BLLCMS_User.Insert(c);
            if (st > 0)
            {
                return Content("<script>alert('添加成功');window.location.href='/HouTaiArea/CMS_User/Index1';</script>");
            }
            else
            {
                return Content("<script>alert('添加失败');window.location.href='/HouTaiArea/CMS_User/Index1';</script>");
            }
        }
        //---------------------------------------------------------------------------------------
        //删除
        public ActionResult Delete(int id)
        {
            int st = BLLCMS_User.Datete(id);
            if (st > 0)
            {
                return Content("<script>alert('删除成功');window.location.href='/HouTaiArea/CMS_User/Index1';</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');window.location.href='/HouTaiArea/CMS_User/Index1';</script>");
            }
        }
        //修改
        public ActionResult Update(int id)
        {
            List<CMS_User> li = BLLCMS_User.Selectid(id);
            return View(li);
        }
        public ActionResult updatestudent(int id, string uname, string upwd, string nname, string mobile, string face, bool admin)
        {
            int st = BLLCMS_User.update(id, uname, upwd, nname, mobile, face, admin);

            if (st > 0)
            {
                return Content("<script>alert('修改成功');window.location.href='/HouTaiArea/CMS_User/Index1';</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');window.location.href='/HouTaiArea/CMS_User/Index1';</script>");
            }
        }
    }
}